#define d3pdrel15_cxx
#include "d3pdrel15.h"
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include "base/particle.h"
#include "Muon.h"
#include "Jet.h"
#include "Electron.h"
#include "TLorentzVector.h"
void d3pdrel15::Loop()
{
//   In a ROOT session, you can do:
//      Root > .L d3pdrel15.C
//      Root > d3pdrel15 t
//      Root > t.GetEntry(12); // Fill t data members with entry number 12
//      Root > t.Show();       // Show values of entry 12
//      Root > t.Show(16);     // Read and show values of entry 16
//      Root > t.Loop();       // Loop on all entries
//

//     This is the loop skeleton where:
//    jentry is the global entry number in the chain
//    ientry is the entry number in the current Tree
//  Note that the argument to GetEntry must be:
//    jentry for TChain::GetEntry
//    ientry for TTree::GetEntry and TBranch::GetEntry
//
//       To read only selected branches, Insert statements like:
// METHOD1:
//    fChain->SetBranchStatus("*",0);  // disable all branches
//    fChain->SetBranchStatus("branchname",1);  // activate branchname
// METHOD2: replace line
//    fChain->GetEntry(jentry);       //read all branches
//by  b_branchname->GetEntry(ientry); //read only this branch
   if (fChain == 0) return;

   Long64_t nentries = fChain->GetEntriesFast();

   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;
      // if (Cut(ientry) < 0) continue;
   }
}

void  d3pdrel15::FillEvtData(unsigned int ient){
    fChain->GetEntry(ient);
    TLorentzVector lv;
    Ntrks=vxp_n;
	
	for(int i=0;i<jet_AntiKt4TopoEM_n;i++){//fill jets
	       Jet aparticle;
               lv.SetPtEtaPhiE(jet_AntiKt4TopoEM_pt->at(i)/1000.,jet_AntiKt4TopoEM_eta->at(i),jet_AntiKt4TopoEM_phi->at(i),jet_AntiKt4TopoEM_E->at(i)/1000.);
		aparticle.setP4(lv);
                aparticle.setEmFrac(jet_AntiKt4TopoEM_emfrac->at(i));
		jets->push_back(aparticle);
		}
	
	for( int i=0;i<mu_staco_n;i++){//fill muons
		Muon aparticle;
               lv.SetPtEtaPhiE(mu_staco_pt->at(i)/1000.,mu_staco_eta->at(i),mu_staco_phi->at(i),mu_staco_E->at(i)/1000.);
		aparticle.setP4(lv);
		aparticle.SetCharge(mu_staco_charge->at(i));
                muons->push_back(aparticle);
		}
   
	for(int i=0;i<el_n;i++){//fill e,ebar
		Electron aparticle;
                lv.SetPtEtaPhiE(el_pt->at(i)/1000.,el_eta->at(i),el_phi->at(i),el_E->at(i)/1000.);
		aparticle.setP4(lv);
                aparticle.SetCharge(el_charge->at(i));
		}
 
  return;
}

void d3pdrel15::SwitchBranches(){
	return;
	}
